﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model._Admin;
using nERP.Model.Fin;

namespace nERP.Model.Fin
{
    /// <summary>
    /// 付款单
    /// </summary>
	[Table("Payment")]
    [SoftKey(nameof(Payment.PayCode))]
    [Display(Name = "_Model.Payment")]
    public class Payment : BasePoco, IPersistPoco, ITenant, IWorkflow
    {
        [Display(Name = "_Model._Payment._PayCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("付款单号")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string PayCode { get; set; }
        [Display(Name = "_Model._Payment._Supplier")]
        [Comment("供应商")]
        [NotMapped]
        public Supplier Supplier { get; set; }
        [Display(Name = "_Model._Payment._Supplier")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("供应商")]
        public string SupplierId { get; set; }
        [Display(Name = "_Model._Payment._SettlementType")]
        [Comment("结算方式")]
        [RefDicName(Name = "结算方式")]
        public DicField SettlementType { get; set; }
        [Display(Name = "_Model._Payment._SettlementType")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("结算方式")]
        public Guid? SettlementTypeId { get; set; }
        [Display(Name = "_Model._Payment._SettlementAccount")]
        [Comment("结算账户")]
        [NotMapped]
        public SettlementAccount SettlementAccount { get; set; }
        [Display(Name = "_Model._Payment._SettlementAccount")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("结算账户")]
        public string SettlementAccountId { get; set; }
        [Display(Name = "_Model._Payment._TotalPrice")]
        [Comment("付款金额")]
        public decimal? TotalPrice { get; set; }
        [Display(Name = "_Model._Payment._MakeUser")]
        [Comment("制单人")]
        [NotMapped]
        public FrameworkUser MakeUser { get; set; }
        [Display(Name = "_Model._Payment._MakeUser")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("制单人")]
        public string MakeUserId { get; set; }
        [Display(Name = "_Model._Buy._InvoicesDate")]
        [Comment("单据日期")]
        public DateTime? PayDate { get; set; }
        [Display(Name = "_Model._Payment._Status")]
        [Comment("状态")]
        public StatusTypeEnum? Status { get; set; }
        [Display(Name = "_Model._Payment._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._Payment._InvoicesImage")]
        [Comment("单据附件")]
        public List<PaymentInvoicesImage> InvoicesImage { get; set; }
        [Display(Name = "_Model._PaymentDetail._Pay")]
        [InverseProperty("Pay")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Fin.PaymentDetail.PayId))]
        public List<PaymentDetail> PaymentDetail_Pay { get; set; }
        [Display(Name = "_Model._Payment._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

    }
    public class PaymentInvoicesImage : TopBasePoco, ISubFile
    {
        public Guid PaymentId { get; set; }
        public Payment Payment { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
